import 'package:flutter/material.dart';
import 'package:flutter_community/pages/home/components/home_list.dart';
import 'package:flutter_community/pages/home/components/home_nav.dart';
import 'package:flutter_community/stores/counter.dart';
import 'package:flutter_community/utils/http.dart';
import 'package:flutter_community/utils/preference.dart';
import 'package:flutter_community/utils/showToast.dart';
import 'package:provider/provider.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  List _NotifyList = [];
  //测试网络请求
  @override
  void initState() {
    super.initState();
    getNotifyList();
  }

  //网络请求
  getNotifyList() async {
    final response = await http.get('/announcement');
    ToastMessage.showSuccess('请求成功');
    //赋值给列表
    setState(() {
      //添加数据
      _NotifyList = response['data'];
    });
    // print(response);
  }

  @override
  Widget build(BuildContext context) {
    final counter = Provider.of<CounterModel>(context);
    return Scaffold(
      appBar: AppBar(
        title: Text('享+社区${counter.counter}'),
        backgroundColor: const Color.fromRGBO(229, 231, 242, 1),
        centerTitle: true,
      ),
      body: Container(
          color: const Color.fromRGBO(229, 231, 242, 1),
          child: Column(
            //顶部导航
            children: [
              HomeNav(),
              HomeList(
                listData: _NotifyList,
              )
            ],
          )),
    );
  }
}
